import React, { Component } from 'react'

class Demo extends Component {
  state = {
    title: '子'
  }
  toParent = ()=> {
    this.props.changeParent(this.state.title)
  }
  render() {
    return(
      <div>
        <h2>{this.state.title}</h2>
        <h2>{this.props.msg}</h2>
        <button onClick={this.toParent}>子传父</button>
      </div>
    )
  }
}

export default class App extends Component {
  state = {
    msg: ''
  } 
  handleChange = (param)=> {
    this.setState({
      msg: param
    })
  }
  render() {
    return (
      <div>
        <Demo 
        changeParent={this.handleChange}
        msg={this.state.msg} />
        <h4>子组件传来的值：{this.state.msg}</h4>
      </div>
    )
  }
}
